package com.test.burnincash.activity_fragment_burnin.base_burnin;

import android.os.Bundle;

import androidx.annotation.Nullable;

import com.test.burnincash.aaahpoppomelo.activity.MainActivity_hpoppomelo;
import com.test.burnincash.bean_burnin.user_info_burnin.LoginInfo_burnin;
import com.test.burnincash.util_burnin.helper_burnin.UserInfoHelper_burnin;
import com.test.burnincash.util_burnin.http_burnin.HttpManager_burnin;
import com.test.burnincash.util_burnin.analytics_burnin.event_burnin.IAnalyticsEvent_burnin;
import com.test.burnincash.util_burnin.analytics_burnin.util_burnin.AnalyticsUtil_burnin;

import org.json.JSONObject;


public abstract class BaseLoginActivity_burnin extends BaseActivity_burnin {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public abstract void onRequestOtpCodeResponse_burnin(String msg,JSONObject jsonObject);

    //登录成功响应
    public void onUserLoginResponse_burnin() {
        try {
            //打点
            String gtype = LoginInfo_burnin.getInstance().getType();
            if (gtype.equalsIgnoreCase(UserInfoHelper_burnin.LOGIN_TYPE_REGISTER)) {
                AnalyticsUtil_burnin.INSTANCE.addEvent(IAnalyticsEvent_burnin.AT_REGISTER);
            }

            //保存登录信息到本地
            UserInfoHelper_burnin.getInstance().setToken(LoginInfo_burnin.getInstance().getToken());
            UserInfoHelper_burnin.getInstance().setUserId(LoginInfo_burnin.getInstance().getUserId());
            UserInfoHelper_burnin.getInstance().setIsAdSource(LoginInfo_burnin.getInstance().getIsAdSource());

            login();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void login(){
        HttpManager_burnin.getInstance().requestUrls();
    }

    //获取Url响应
    public void onRequestUrlsResponse(){
        //登录前初始化
        AnalyticsUtil_burnin.INSTANCE.initDevice(BaseApplication_burnin.getApplication_burnin());
        AnalyticsUtil_burnin.INSTANCE.saveFirebaseAndFacebookS2SInfo();

        if (UserInfoHelper_burnin.getInstance().isAdSource()){
            //请求用户流程信息
            HttpManager_burnin.getInstance().requestUserProcess();
        }else {
            startActivityForSingleTop_burnin(MainActivity_hpoppomelo.class);
        }
    }

}